Final Tune-up and Deployment
============================

We are close to finish our blog application. Before deployment, we would like to do some tune-ups.


Changing Home Page
------------------

We change to use the post list page as the home page. We modify the [application configuration](http://www.yiiframework.com/doc/guide/basics.application#application-configuration) as follows,

~~~
[php]
return array(
	......
	'defaultController'=>'post',
	......
);
~~~

> Tip: Because `PostController` already declares `index` to be its default action, when we access the home page of the application, we will see the result generated by the `index` action of the post controller.


Enabling Schema Caching
-----------------------

Because ActiveRecord relies on the metadata about tables to determine the column information, it takes time to read the metadata and analyze it. This may not be a problem during development stage, but for an application running in production mode, it is a total waste of time if the database schema does not change. Therefore, we should enable the schema caching by modifying the application configuration as follows,

~~~
[php]
return array(
	......
	'components'=>array(
		......
		'cache'=>array(
			'class'=>'CDbCache',
		),
		'db'=>array(
			'class'=>'system.db.CDbConnection',
			'connectionString'=>'sqlite:/wwwroot/blog/protected/data/blog.db',
			'schemaCachingDuration'=>3600,
		),
	),
);
~~~

In the above, we first add a `cache` component which uses a default SQLite database as the caching storage. If our server is equipped with other caching extensions, such as APC, we could change to use them as well. We also modify the `db` component by setting its [schemaCachingDuration|CDbConnection::schemaCachingDuration] property to be 3600, which means the parsed database schema data can remain valid in cache for 3600 seconds.


Disabling Debugging Mode
------------------------

We modify the entry script file `/wwwroot/blog/index.php` by removing the line defining the constant `YII_DEBUG`. This constant is useful during development stage because it allows Yii to display more debugging information when an error occurs. However, when the application is running in production mode, displaying debugging information is not a good idea because it may contain sensitive information such as where the script file is located, and the content in the file, etc.


Deploying the Application
-------------------------

The final deployment process manly involves copying the directory `/wwwroot/blog` to the target directory. The following checklist shows every needed step:

 1. Install Yii in the target place if it is not available;
 2. Copy the entire directory `/wwwroot/blog` to the target place;
 3. Edit the entry script file `index.php` by pointing the `$yii` variable to the new Yii bootstrap file;
 4. Edit the file `protected/yiic.php` by setting the `$yiic` variable to be the new Yii `yiic.php` file;
 5. Change the permission of the directories `assets` and `protected/runtime` so that they are writable by the Web server process.


